#include "Clock.h"

uint32_t clockmills = 0;

void Clock_init()
{
    uint8_t clock = CLOCK_TIMER;
    clockmills = 0;
    switch (clock)
    {
    case CLOCK_TIMER0:
        TIM0_TimeBaseInit(PRESSEL_FSYS_D12, TIM0_MODE_TIMER);
        CLOCK_TIM0_WorkModeConfig(CLOCK_SetCounter);
        TIM0_ITConfig(ENABLE, LOW);
        TIM0_Cmd(ENABLE);
        break;
    case CLOCK_TIMER1:
        break;
    case CLOCK_TIMER2:
        break;
    case CLOCK_TIMER3:
        break;
    case CLOCK_TIMER4:
        break;
    }
}

uint32_t Clock_mills()
{
    return clockmills;
}

#if (CLOCK_TIMER == CLOCK_TIMER0)

void timer0Interrupt(void) interrupt 1
{
    clockmills++;
    TIM0_Mode0SetReloadCounter(CLOCK_SetCounter);
}

#endif
